<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>第四种方法</title>
</head>

<body>
  <h4>请写出下面</h4>
  <section class="code">
    <code>var arr=['a', ['b', 'c'], 2, ['d', 'e', 'f'], 'g', 3, 4];flat(arr)//a,b,c,2,d,e,f,g,3,4</code>
    <script type="text/javascript">
      // Iterator
      Array.prototype[Symbol.iterator] = function () {
          let arr = [].concat(this);
          // arr=['a', ['b', 'c'], '2', ['d', 'e', 'f'], 'g', 3, 4]
          let getFirst = function (array) {
              let first = array.shift();
              return first;
          };
          return {
              next: function () {
                  let item = getFirst(arr);
                  if (item) {
                      return {
                          value: item,
                          done: false,
                      };
                  } else {
                      return {
                          done: true,
                      };
                  }
              },
          };
      };
      var flat = function (arr) {
          let r = [];
          for (let i of arr) { r.push(i); }
          return r.join(',');
      };
      var arr = ['a', ['b', 'c'], '2', ['d', 'e', 'f'], 'g', 3, 4];
      console.log(flat(arr));


    </script>
  </section>
</body>

</html>
